#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int mod = 998244353;
const int N = 20;
const int MS = 262146;

int n,q,rt,U,S,h[N],cnt,deg[N];
ll A[N],B[N],f[MS];
struct edge{int v,nxt;}e[N<<1];
void link(int x,int y){e[++cnt] = (edge){y,h[x]};h[x] = cnt;}

ll qp(ll x,int t){ll res=1;for(;t;t>>=1,x=x*x%mod)if(t&1)res=res*x%mod;return res;}

int popcnt(int x){int res=0;for(;x;x>>=1)res+=x&1;return res;}

void dfs(int x,int p){
	A[x] = B[x] = 0;
	if(S >> x - 1 & 1) return;
	ll tota = 0,totb = 0;
	for(int i = h[x],y;i;i = e[i].nxt){
		if((y = e[i].v) == p) continue;
		dfs(y,x); tota = (tota + A[y]) % mod; totb = (totb + B[y]) % mod;
	}
	A[x] = qp((deg[x]-tota+mod)%mod,mod-2)%mod,B[x] = (totb + deg[x]) % mod * A[x] % mod;
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,q = in,rt = in;
	for(int i = 1,u,v;i < n;i++){deg[u = in]++,deg[v = in]++; link(u,v); link(v,u);}
	U = 1 << n;
	for(S = 1;S < U;S++){dfs(rt,0); f[S] = popcnt(S) & 1 ? B[rt] : (mod - B[rt]) % mod;}
	for(int h = 2;h <= U;h<<=1){
		for(int i = 0,j = h >> 1;i < U;i+=h)
			for(int k = i;k < i + j;k++)
				(f[k+j] += f[k]) %= mod;
	}
	while(q--){
		S = 0;int k = in;while(k--) S |= 1 << in - 1;
		printf("%lld\n",f[S]%mod);
	}
	return 0;
}

